package com.glsc.ngateway.common.base.domain.mysql.gateway.platform.flow;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.glsc.ngateway.common.api.flowable.resp.ResponseSituationDto;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Appendix;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Data
@Table(name = "t_gw_flow_form_event")
@org.hibernate.annotations.Table(appliesTo = "t_gw_flow_form_event",comment = "事件管理流程form表单")
public class FlowFormEvent implements Serializable {

    @ApiModelProperty(value = "流程ID")
    @Id
//    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "process_id", columnDefinition = "varchar(60) comment '唯一编号'")
    private String processId;

    @ApiModelProperty(value = "流程创建时间")
    @org.hibernate.annotations.CreationTimestamp
    @Column(name = "process_create_time", columnDefinition = "datetime comment '发起时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime processCreateTime;

    @ApiModelProperty(value = "事件发生时间")
    @Column(name = "event_happen_time", columnDefinition = "datetime comment '事件发生时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    private LocalDate eventHappenTime;

    /**
     * 流程标题
     */
    @ApiModelProperty(value = "流程标题")
    @Column(name = "process_title", columnDefinition = "varchar(1024) comment '流程标题'")
    String processTitle;

    /**
     * 事件标题
     */
    @ApiModelProperty(value = "事件标题")
    @Column(name = "event_title", columnDefinition = "varchar(1024) comment '事件标题'")
    String eventTitle;


    /**
     * 发起人姓名
     */
    @ApiModelProperty(value = "发起人姓名")
    @Column(name = "flow_create_operator_name", columnDefinition = "varchar(30) comment '发起人姓名'")
    String flowCreateOperatorName;

    /**
     * 发起人账号oa
     */
    @ApiModelProperty(value = "发起人账号oa")
    @Column(name = "flow_create_operator_account", columnDefinition = "varchar(30) comment '发起人账户'")
    String flowCreateOperatorAccount;

    @ApiModelProperty(value = "发起人部门名称")
    @Column(name = "flow_creator_department", columnDefinition = "varchar(30) comment '发起人部门名称'")
    String flowCreatorDepartment;

    /**
     * 系统名称
     */
    @ApiModelProperty(value = "系统名称")
    @Column(name = "system_name", columnDefinition = "varchar(200) comment '系统名称，从it网关取'")
    private String systemName;

    /**
     * 系统代码
     */
    @ApiModelProperty(value = "系统代码")
    @Column(name = "system_code", columnDefinition = "varchar(30) comment '系统名称，从it网关取，后续关联团队人员'")
    private String systemCode;

    /**
     * 系统管理员姓名
     */
    @ApiModelProperty(value = "系统管理员姓名")
    @Column(name = "system_admin_name", columnDefinition = "varchar(30) comment '系统管理员姓名'")
    private String systemAdminName;


    /**
     *系统管理员账号oa
     */
    @ApiModelProperty(value = "系统管理员账号oa")
    @Column(name = "system_admin_account", columnDefinition = "varchar(30) comment '系统管理员账户'")
    private String systemAdminAccount;

    /**
     * 系统管理员姓名
     */
    @ApiModelProperty(value = "系统归属部门")
    @Column(name = "system_belong_department", columnDefinition = "varchar(50) comment '系统归属部门'")
    private String systemBelongDepartment;

    @ApiModelProperty(value = "事件概述")
    @Column(name = "event_summary", columnDefinition = "Text comment '事件概述'")
    private String eventSummary;

    @ApiModelProperty(value = "事件状态 字典")
    @Column(name = "event_status", columnDefinition = "varchar(10) comment '事件状态'")
    private String eventStatus;

    @ApiModelProperty(value = "事件分类 字典")
    @Column(name = "event_class", columnDefinition = "varchar(10) comment '事件分类'")
    private String eventClass;

    @ApiModelProperty(value = "事件分级 字典")
    @Column(name = "event_grade", columnDefinition = "varchar(10) comment '事件分级'")
    private String eventGrade;

    @ApiModelProperty(value = "外部事件分类 字典")
    @Column(name = "event_class_external", columnDefinition = "varchar(10) comment '事件外部分类'")
    private String eventClassExternal;

    @ApiModelProperty(value = "外部事件分级 字典")
    @Column(name = "event_grade_external", columnDefinition = "varchar(10) comment '事件外部分级'")
    private String eventGradeExternal;

    @ApiModelProperty(value = "事件结果 ")
    @Column(name = "event_result", columnDefinition = "Text comment '事件结果'")
    private String eventResult;

    @ApiModelProperty(value = "事件报告 暂时不需要，应该使用事件报告文件 ")
    @Column(name = "event_report", columnDefinition = "varchar(100) comment '事件报告'")
    private String eventReport;

    @ApiModelProperty(value = "事件报告文件")
    @Column(name = "event_report_doc_id_list", columnDefinition = "varchar(100) comment '事件报告附件列表'")
    private String eventReportDocIdList;

    @ApiModelProperty(value = "事件报告文件")
    @Transient
    private List<Appendix> eventReportDocList;

    @ApiModelProperty(value = "是否完成 ")
    @Column(name = "is_close", columnDefinition = "int(2) comment '是否完成0 未完成 1已完成'")
    private int isClose = 0;

    @ApiModelProperty(value = "事件成因")
    @Column(name = "event_cause", columnDefinition = "int(2) comment '是否外部0 内部 1外部'")
    private Integer eventCause;

    @ApiModelProperty(value = "创建时间")
    @Column(name = "insert_time", columnDefinition = "datetime comment '创建时间'")
    @org.hibernate.annotations.CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime insertTime;

    @ApiModelProperty(value = "更新时间")
    @Column(name = "update_time", columnDefinition = "datetime comment '更新时间'")
    @org.hibernate.annotations.UpdateTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime updateTime;


    /**
     *
     * TODO 暂时这样
     * * * * */
    public static FlowFormEvent instance(ResponseSituationDto r) {
        return new FlowFormEvent();
    }

    /**
     * 整改措施
     */
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "process_id", referencedColumnName = "process_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    @Where(clause = " be_deleted=0 ")//仅未删除状态的
    @ApiModelProperty(value = "整改明细")
    List<FlowFormEventDetailImprove> detailImproves;
}
